<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电影列表</title>
    <%- include common %>
</head>
<body>
    <%- include('head', {title: 'movies', username: username}) %>

    <div class="container-fluid">
        <div class="container">
            <h3 class="text-primary">电影列表</h3>

            <div class="row">
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <button style="margin-top: 10px;" class="btn btn-primary" onclick="location.href='/movies?year=1'">
                        年份升序
                    </button>
                    <button style="margin-top: 10px;" class="btn btn-info" onclick="location.href='/movies?year=-1'">
                        年份降序
                    </button>
                    <button style="margin-top: 10px;" class="btn btn-danger" onclick="location.href='/movies?rating.average=1'">
                        评分升序
                    </button>
                    <button style="margin-top: 10px;" class="btn btn-warning" onclick="location.href='/movies?rating.average=-1'">
                        评分降序
                    </button>
                </div>
            </div>

            <div class="row" style="margin-top:10px;">
                <div class="col-md-3 col-sm-6 col-xs-12">
                    <div class="form-group" style="display: flex">
                        <input type="text" id="keyword" class="form-control" placeholder="请输入搜索关键词">
                        <button class="btn btn-danger" onclick="searchDone()">
                            电影搜索
                        </button>
                    </div>
                </div>
            </div>

            <div class="row">
                <% if (result.length > 0) { %>
                    <% result.forEach((item, index) => { %>
                        <div class="col-md-3 col-sm-6 col-xs-12">
                            <!-- thumbnail 图文混排 -->
                            <a href="/comment/mdetail?mid=<%- item.id %>">
                                <div class="thumbnail" style="cursor: pointer;">
                                    <img src="<%- item.images.large.replace(/img7/, 'img3') %>" alt="" style="height: 240px; width: 100%;">
                                    <div>
                                        <p class="text-primary"><%- item.title %></p>
                                        <p class="text-info">年份：<%- item.year %></p>
                                        <p class="text-danger">评分：<%- item.rating.average %></p>
                                        <p class="text-warning">分类：<%- item.genres %></p>
                                    </div>
                                </div>
                            </a>
                        </div>
                    <% }) %>
                <% } else { %>
                    <h3 class="text-center text-danger">暂无电影数据</h3>
                <% } %>
                
            </div>
        </div>
    </div>

    <%- include foot %>


    <script>
        function searchDone(){
            location.href = '/movies?keyword=' + $("#keyword").val();
        }
    </script>

</body>
</html>